import 'package:base_plugin/base_plugin.dart';
import 'package:dio/dio.dart';
import 'package:finance_app/src/common/config.dart';

/// 用户
class HttpUserService {
  /// 获取用户信息
  static Future<Response> getMyProfile() {
    return BaseConfig.httpBase.postJson('/api/users/me', {
      'notification_token': Config.pushKey,
    });
  }

  /// 更新用户信息
  static Future<Response> updateMyProfile({
    String name,
    String password,
    String nickname,
    String avatar,
    String email,
    String notificationToken,
  }) {
    return BaseConfig.httpBase.postJson('/api/users/me', {
      "name": name,
      "nickname": nickname,
      "email": email,
      "avatar": avatar,
      "notification_token": notificationToken,
      "password": password,
    });
  }

  /// 更新密码
  static Future<Response> updateMyProfilePassword(String password) {
    return BaseConfig.httpBase.putJson('/api/users/me/password', {
      'password': password,
    });
  }

  /// 更新手机号码
  static Future<Response> updateMyProfilePhoneNumber(
      String countryCode, String phoneNumber, String otp) {
    return BaseConfig.httpBase.postJson('/api/users/me/phone_number',
        {"country_code": countryCode, "phone_number": phoneNumber, "otp": otp});
  }

  /// 更新email
  static Future<Response> updateMyProfileEmail(String email, String otp) {
    return BaseConfig.httpBase
        .postJson('/api/users/me/email', {"email": email, "otp": otp});
  }

  /// 更新密码
  static Future<Response> updatePassword(
      String currentPassword, String newPassword) {
    return BaseConfig.httpBase.postJson('/api/users/me/password', {
      'new_password': newPassword,
      'current_password': currentPassword,
    });
  }

  /// 登出
  static Future<Response> logout() {
    return BaseConfig.httpBase.postJson('/api/users/me/logout', {
      'player_id': Config.pushKey,
    });
  }
}
